package com.ls.bigdata.handler;

import com.alibaba.fastjson.JSON;
import com.ls.bigdata.entity.User;
import com.ls.bigdata.filter.CaptchaFilter;
import com.ls.bigdata.utils.R;
import com.ls.bigdata.utils.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @program: springsecurity-test
 * @author: lishun
 * @create: 2021-08-29 16:26
 **/
@Component
public class AuthenticationSuccessHandlerIml implements AuthenticationSuccessHandler {


    @Override
    public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        httpServletResponse.setContentType("application/json;charset=UTF-8");
        // 返回用户数据
        User admin = User.builder().username("admin").avatar("https://www.static.talkxj.com/config/43a07ac1ca201143f7b938d0791124fc.png").build();
        httpServletResponse.getWriter().write(JSON.toJSONString(R.ok(ResultCode.LOGIN_ok,admin)));

    }


}
